package li.webqq.util;

import java.awt.FlowLayout;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * @author 明伟
 */
public class WindowsUtil {
    public static void showWin(final byte[] data) {
        try {
            JFrame frame = new JFrame("验证码(请不要关这个窗口,关了程序就停了)");
            frame.setLocationRelativeTo(null);
            JPanel imagePanel = (JPanel) frame.getContentPane();

            ImageIcon imageIcon = new ImageIcon(data);
            JLabel label = new JLabel(imageIcon);

            label.setBounds(0, 0, imageIcon.getIconWidth(), imageIcon.getIconHeight());

            imagePanel = (JPanel) frame.getContentPane();
            imagePanel.setOpaque(false);
            imagePanel.setLayout(new FlowLayout());

            frame.getLayeredPane().setLayout(null);
            frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(500, 300);
            frame.setVisible(true);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}